package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.CategoryId;
import com.cskaoyan.bean.wx.WxBaseRespVo;
import com.cskaoyan.bean.wx.WxCollectVO;
import com.cskaoyan.service.wx.WxCatalogService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/wx/catalog/")
public class WxCatalogController {
    @Autowired
    WxCatalogService wxCatalogService;
    @RequestMapping("index")
    public WxBaseRespVo catelogindex(){
        List<CategoryId> categoryList = wxCatalogService.queryCategoryByPid(0);
        List<CategoryId> currentSubCategory = wxCatalogService.queryCategoryByPid(categoryList.get(0).getPid());
        CategoryId currentCategory = categoryList.get(0);
        HashMap<String, Object> data = new HashMap<>();
        data.put("categoryList",categoryList);
        data.put("currentSubCategory",currentSubCategory);
        data.put("currentCategory",currentCategory);
        return WxBaseRespVo.ok(data);
    }

    @RequestMapping("current")
    public WxBaseRespVo current(Integer id){
        int pid = id;
        List<CategoryId> currentCategory = wxCatalogService.queryCategoryByidNpid(id,0);
        List<CategoryId> currentSubCategory = wxCatalogService.queryCategoryByPid(pid);
        HashMap<String, Object> data = new HashMap<>();
        data.put("currentSubCategory",currentSubCategory);
        data.put("currentCategory",currentCategory.get(0));
        return WxBaseRespVo.ok(data);
    }
}
